home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / AIFF DSP v22 / plugin_src / num_input_macros.h < prev    next >
Text File  |  1995-01-30  |  592b  |  18 lines

  1. /* macros useful for numerical input */
  2.  
  3. #define GET_NUM_P( prompt, scanfmt, x ) \
  4.    fprintf( stderr, prompt " (must be positive): " ); \
  5.    GET_NUM_COND( scanfmt, x, (x) > 0 )
  6.  
  7. #define GET_NUM_RANGE( prompt, printfmt, scanfmt, x, min, max ) \
  8.    fprintf( stderr, prompt " [" printfmt "..." printfmt "]: ", min, max ); \
  9.    GET_NUM_COND( scanfmt, x, (x) >= (min) && (x) <= (max) )
  10.  
  11. #define GET_NUM_COND( scanfmt, x, cond ) \
  12.    while ( !( scanf( scanfmt, &(x) ) && (cond) ) ) \
  13.    { \
  14.       getchar(); \
  15.       fprintf( stderr, "Try again (last input was illegal): " ); \
  16.    } \
  17.    getchar()
  18.